#ifndef SIGAMER_H
#define SIGAMER_H

/** 
 * @brief Automate for game
 */
class SIGamer
{
    public:
        enum SIState {
            INIT,       //init
            STARTGAME,  //start of game
            QREADING,   //question reading
            ASWAIT,     //waiting of answer from any player
            A1WAIT      //waiting of answer from one player
        }; /* SIState */
        enum Player
        {
            RED = 0, GREEN, BLUE, YELLOW
        }; /*         enum Player */

        /** 
         * @brief Input signals for gamer
         */
        enum InSignal
        {
            GOTO = -1,
            REDPLAYER,
            GREENPLAYER,
            BLUEPLAYER,
            YELLOWPLAYER,
            PLUS,
            MINUS
        }; /*         enum InSignal */
        
        /** 
         * @brief Ctor
         */
        SIGamer();

        /** 
         * @brief Jumps to tne next state of game 
         */
        void nextState(InSignal iSignal = GOTO);
        /** 
         * @brief Returns current state of game
         */
        int state() const;
        /** 
         * @brief Returns player's score
         * 
         * @param iPlayer number of player which score will be returned
         */
        int playerScore(Player iPlayer) const;
        /** 
         * @brief Sets player's score
         * 
         * @param iPlayer number of player
         * @param iScore  new score
         * @warning don't check values
         */
        void setPlayerScore(Player iPlayer, int iScore);
        /** 
         * @brief Returns number of current question.
         */
        int curQNum() const;
        /** 
         * @brief Return cost of current question. 
         */
        int curQCost() const;
        /** 
         * @brief Returns current theme's num
         */
        int curThemeNum() const;
        /** 
         * @brief Returns number of current player (which answer is wait)
         */
        int curPlayer() const;
        /** 
         * @brief Resets gamer state: sets to initial values counter and
         * jumps to QREADING state
         */
        void reset();
    private:
        /** 
         * @brief Jumps to reading of next question
         */
        void nextQuestion();

        int state_;     /*!< state of game */
        int prevState_; /*!< for returning from state QREADING or ASWAIT when answer is wrong */
        int curQCost_;  /*!< cost of current question */
        int curQNum_;   /*!< number of current question */
        int curThemeNum_;   /*!, num cur theme */
        int score_[4];  /*!< scores of players */
        int curPlayer_; /*!< number of answers player */
}; /* class SiGamer */

inline
SIGamer::SIGamer():
    state_(STARTGAME)
{
} /* SIGamer::SIGamer() */

inline
int SIGamer::state() const
{
    return state_;
} /* SIGamer::state() const */

inline        
int SIGamer::playerScore(Player iPlayer) const
{
    return score_[iPlayer];
} /* int playerScore(Player iPlayer) const */

inline        
int SIGamer::curQNum() const
{
    return curQNum_;
} /* int SIGamer::curQNum() const */

inline        
int SIGamer::curQCost() const
{
    return curQCost_;
} /* int SIGamer::curQCost() const */

inline
int SIGamer::curThemeNum() const
{
    return curThemeNum_;
} /* int SIGamer::curThemeNum() const */

inline
int SIGamer::curPlayer() const
{
    return curPlayer_;
} /* int SIGamer::curPlayer() const */

inline        
void SIGamer::reset()
{
    state_ = STARTGAME;
    nextState();
}

inline        
void SIGamer::setPlayerScore(Player iPlayer, int iScore)
{
    score_[iPlayer] = iScore;
} /* void SIGamer::setPlayerScore(Player iPlayer, int iScore) */

#endif //SIGAMER_H

